home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Simulation / PDP-8 Simulator / Source Code / PDPMenus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-13  |  4.8 KB  |  238 lines  |  [TEXT/KAHL]

  1. /*************************************************************************************
  2. *
  3. *        Generic Appshell- a system 7.0 compatible application shell
  4. *
  5. *        ©1992 Graham Cox. All Rights Reserved.
  6. *
  7. *        This file contains code which may require modification to incorporate your
  8. *        application's functionality. This file contains menu disatch functions.
  9. *
  10. *        Modification History:
  11. *        10/2/92 created from scratch.    
  12. *
  13. *
  14. *
  15. *************************************************************************************/
  16.  
  17. #include    "PDPGlobalEqu.p"
  18. #include    "EditGlobalEqu.p"
  19.  
  20. #include "PDPMenus.proto.h"
  21.  
  22. textEdHdl GetWEditRecord(WindowPtr theWindow);
  23. char        IsEditKind(WindowPtr);
  24.  
  25. extern     int            done;
  26. extern    MenuHandle    AppMenus[NumMenus];
  27.  
  28. int        AssemblyDest = toMemory;
  29.  
  30. ProcessRecHdl    GetProcess(WindowPtr theWindow);
  31. PDPRegHdl        GetCPU(WindowPtr theWindow);
  32. PDPMemHdl        GetMemory(WindowPtr theWindow);
  33. PrefsRecHdl        GetPrefs(WindowPtr theWindow);
  34. int                SetTargetProcess(long currentProcess);
  35.  
  36.  
  37.  
  38. FileMenu(int    theItem)
  39. {
  40.     /* handle file menu commands */
  41.     SFReply        fReply;
  42.     
  43.     switch (theItem) {
  44.         case ItemNew:
  45.             OpenNewWindow();
  46.             break;
  47.         case ItemOpen:
  48.             OpenSourceCode();
  49.             break;
  50.         case ItemClose:
  51.             CloseTheWindow(FrontWindow());
  52.             break;
  53.         case ItemSaveAs:
  54.         case ItemSave:
  55.             break;
  56.         case ItemPageSetup:
  57.             break;
  58.         case ItemPrint:
  59.             break;
  60.         case ItemQuit:
  61.             done = TRUE;
  62.             break;
  63.         default:
  64.             break;
  65.     }
  66. }
  67.  
  68.  
  69. EditMenu(int    theItem)
  70. {
  71.     /* handle edit menu commands */
  72.     
  73.     if (! SystemEdit(theItem-1)) {
  74.         switch(theItem) {
  75.             case ItemUndo:
  76.                 break;
  77.             case ItemCut:
  78.                 break;
  79.             case ItemCopy:
  80.                 break;
  81.             case ItemPaste:
  82.                 break;
  83.             case ItemClear:
  84.                 break;
  85.             case ItemShowClip:
  86.                 break;
  87.             default:
  88.                 break;
  89.         }
  90.     }
  91. }
  92.  
  93.  
  94. PDPMenu(int theItem)
  95. {
  96.     /* dispatches menu selections from PDP-8 menu */
  97.     Str32    mString;
  98.     
  99.     switch (theItem) {
  100.         case ItemGo:
  101.             ResumePDP(FrontWindow());
  102.             break;
  103.         case ItemHalt:
  104.             StopPDP(FrontWindow());
  105.             break;
  106.         case ItemReset:
  107.             ResetPDP(FrontWindow());
  108.             break;
  109.         case ItemSingleStep:
  110.             StepPDP(FrontWindow());
  111.             break;
  112.         case ItemScrollToPC:
  113.             ScrollToPC(FrontWindow());
  114.             break;
  115.         case ItemGetInfo:
  116.             ClearProcessMem(FrontWindow());
  117.             MarkForUpdate(FrontWindow());
  118.             break;
  119.         case ItemPreferences:
  120.             PDPPreferences(GetPrefs(FrontWindow()));
  121.             MarkForUpdate(FrontWindow());
  122.             break;
  123.         case ItemStack:
  124.             StackWindows();
  125.             break;
  126.         case ItemShowRuler:
  127.             if (ShowHideRulers(FrontWindow()))
  128.                 /* showing ruler */
  129.                 GetIndString(&mString,standardResID,13);
  130.             else
  131.                 /* hiding ruler */
  132.                 GetIndString(&mString,standardResID,12);
  133.             SetItem(AppMenus[pdpMenu],ItemShowRuler,&mString);
  134.             break;
  135.         default:
  136.             break;
  137.     }
  138. }
  139.  
  140.  
  141. AssembleMenu(MenuHandle theMenu,int theItem)
  142. {
  143.     /* dispatches commands from assemble menu */
  144.     int        aHit;
  145.     SFReply    fReply;
  146.     extern int    TargetProcessID;
  147.     
  148.     switch (theItem) {
  149.         case ItemAssemble:
  150.             PDPAssembleCode(FrontWindow());
  151.             break;
  152.         case ItemToDisk:
  153.             CheckItem(theMenu,ItemToMemory,FALSE);
  154.             CheckItem(theMenu,ItemToDisk,TRUE);
  155.             AssemblyDest = toDisk;
  156.             break;
  157.         case ItemToMemory:
  158.             CheckItem(theMenu,ItemToMemory,TRUE);
  159.             CheckItem(theMenu,ItemToDisk,FALSE);
  160.             AssemblyDest = toMemory;
  161.             TargetProcessID = SetTargetProcess(TargetProcessID);
  162.             break;
  163.         case ItemToBasingstoke:
  164.             aHit = xAlert(133,NIL);
  165.             break;
  166.         case ItemLoadObject:
  167.             ChooseObjectFile(&fReply);
  168.             PDPLoad(FrontWindow(),&fReply);
  169.             break;
  170.         default:
  171.             break;
  172.     }    
  173. }
  174.  
  175.  
  176. OpenNewWindow(void)
  177. {
  178.     /* opens new untitled window from default res template */
  179.     
  180.     WindowPtr    w;
  181.     
  182.     w = GetNewWindow(standardResID,NIL,(WindowPtr)-1L);
  183.     if (w != NIL) {
  184.         InitProcessWindow(w);
  185.         ShowWindow(w);
  186.         SelectWindow(w);
  187.     }
  188. }
  189.  
  190.  
  191. ChooseObjectFile(SFReply *theReply)
  192. {
  193.     /* presents SF Open dialog box for object files */
  194.     
  195.     SFTypeList            theList;
  196.     Point                where;
  197.     
  198.     theList[0] = 'OBJF';
  199.     SetPt(&where,100,100);
  200.     SFDialogLocation(getDlgID,&where);
  201.     SFGetFile(where,(ConstStr255Param)'/p',NIL,2,&theList,NIL,theReply);
  202. }
  203.  
  204.  
  205. MenuAdjust(void)
  206. {
  207.     /* call before a menu selection to enable/disable items according to current window
  208.         type at front */
  209.     int            i,th;
  210.     textEdHdl    theText;
  211.     Str32        mTxt;
  212.         
  213.     if (IsSimulator(FrontWindow())) {
  214.         EnableItem(AppMenus[pdpMenu],ItemScrollToPC);
  215.         EnableItem(AppMenus[pdpMenu],ItemPreferences);
  216.         EnableItem(AppMenus[asmMenu],ItemLoadObject);
  217.     }
  218.     else {
  219.         DisableItem(AppMenus[pdpMenu],ItemScrollToPC);
  220.         DisableItem(AppMenus[pdpMenu],ItemPreferences);
  221.         DisableItem(AppMenus[asmMenu],ItemLoadObject);
  222.     }
  223.     if (IsEditKind(FrontWindow())) {
  224.         theText = GetWEditRecord(FrontWindow());
  225.         th = GetTabBarHeight(theText);
  226.         if (th)
  227.             GetIndString(&mTxt,standardResID,13);
  228.         else
  229.             GetIndString(&mTxt,standardResID,12);
  230.         SetItem(AppMenus[pdpMenu],ItemShowRuler,&mTxt);
  231.         EnableItem(AppMenus[asmMenu],ItemAssemble);
  232.         EnableItem(AppMenus[pdpMenu],ItemShowRuler);
  233.     }
  234.     else {    
  235.         DisableItem(AppMenus[asmMenu],ItemAssemble);
  236.         DisableItem(AppMenus[pdpMenu],ItemShowRuler);
  237.     }
  238. }